import 'package:e_book/pages/root/root_page.dart';
import 'package:e_book/pages/theme/dark.theme.dart';
import 'package:e_book/pages/theme/theme_provider.dart';
import 'package:e_book/utils/toast_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

Size get designSize {
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  // 逻辑短边
  final logicaShortestSize =
      firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  // 逻辑长边
  final logicaLongestSize =
      firstView.physicalSize.longestSide / firstView.devicePixelRatio;
  // 缩放比例
  const scaleFactor = 0.95;
  return Size(
      logicaShortestSize * scaleFactor, logicaLongestSize * scaleFactor);
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: designSize,
        builder: (context, child) {
          return MaterialApp(
            navigatorKey: ToastUtils.navigatorKey,
            debugShowCheckedModeBanner: false,
            theme: Provider.of<ThemeProvider>(context, listen: false).themeData,
            darkTheme: darkMode,
            home: const RootPage(),
          );
        });
  }
}
